from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-12-26 14:02:42.791935
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 26, Dec, 2022
Time: 14:02:49
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.3114
Nobs: 882.000 HQIC: -51.6128
Log likelihood: 11670.0 FPE: 3.19018e-23
AIC: -51.7994 Det(Omega_mle): 2.88236e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297774 0.049549 6.010 0.000
L1.Burgenland 0.105995 0.033906 3.126 0.002
L1.Kärnten -0.106868 0.018216 -5.867 0.000
L1.Niederösterreich 0.212721 0.071112 2.991 0.003
L1.Oberösterreich 0.083740 0.067277 1.245 0.213
L1.Salzburg 0.250535 0.036002 6.959 0.000
L1.Steiermark 0.030708 0.047291 0.649 0.516
L1.Tirol 0.127498 0.038473 3.314 0.001
L1.Vorarlberg -0.061812 0.033098 -1.868 0.062
L1.Wien 0.063991 0.060023 1.066 0.286
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063686 0.101819 0.625 0.532
L1.Burgenland -0.009139 0.069674 -0.131 0.896
L1.Kärnten 0.049157 0.037433 1.313 0.189
L1.Niederösterreich -0.171853 0.146129 -1.176 0.240
L1.Oberösterreich 0.360136 0.138249 2.605 0.009
L1.Salzburg 0.285822 0.073982 3.863 0.000
L1.Steiermark 0.109436 0.097179 1.126 0.260
L1.Tirol 0.319469 0.079059 4.041 0.000
L1.Vorarlberg 0.025048 0.068013 0.368 0.713
L1.Wien -0.025841 0.123342 -0.210 0.834
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.200494 0.025717 7.796 0.000
L1.Burgenland 0.090676 0.017598 5.153 0.000
L1.Kärnten -0.009212 0.009455 -0.974 0.330
L1.Niederösterreich 0.267569 0.036908 7.250 0.000
L1.Oberösterreich 0.110375 0.034918 3.161 0.002
L1.Salzburg 0.053610 0.018686 2.869 0.004
L1.Steiermark 0.016171 0.024545 0.659 0.510
L1.Tirol 0.102929 0.019968 5.155 0.000
L1.Vorarlberg 0.056998 0.017178 3.318 0.001
L1.Wien 0.111388 0.031153 3.576 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.104640 0.026364 3.969 0.000
L1.Burgenland 0.048057 0.018041 2.664 0.008
L1.Kärnten -0.017047 0.009692 -1.759 0.079
L1.Niederösterreich 0.197972 0.037837 5.232 0.000
L1.Oberösterreich 0.276711 0.035797 7.730 0.000
L1.Salzburg 0.117983 0.019156 6.159 0.000
L1.Steiermark 0.100595 0.025163 3.998 0.000
L1.Tirol 0.127249 0.020471 6.216 0.000
L1.Vorarlberg 0.070047 0.017611 3.978 0.000
L1.Wien -0.027038 0.031937 -0.847 0.397
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131868 0.047570 2.772 0.006
L1.Burgenland -0.053682 0.032552 -1.649 0.099
L1.Kärnten -0.037117 0.017489 -2.122 0.034
L1.Niederösterreich 0.166724 0.068272 2.442 0.015
L1.Oberösterreich 0.131728 0.064590 2.039 0.041
L1.Salzburg 0.290782 0.034565 8.413 0.000
L1.Steiermark 0.034766 0.045403 0.766 0.444
L1.Tirol 0.162267 0.036937 4.393 0.000
L1.Vorarlberg 0.108212 0.031776 3.405 0.001
L1.Wien 0.066008 0.057626 1.145 0.252
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061465 0.037721 1.629 0.103
L1.Burgenland 0.038964 0.025812 1.510 0.131
L1.Kärnten 0.049885 0.013868 3.597 0.000
L1.Niederösterreich 0.227173 0.054136 4.196 0.000
L1.Oberösterreich 0.267242 0.051216 5.218 0.000
L1.Salzburg 0.060020 0.027408 2.190 0.029
L1.Steiermark -0.006434 0.036002 -0.179 0.858
L1.Tirol 0.157734 0.029288 5.386 0.000
L1.Vorarlberg 0.069268 0.025197 2.749 0.006
L1.Wien 0.075369 0.045694 1.649 0.099
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185936 0.045228 4.111 0.000
L1.Burgenland 0.018008 0.030949 0.582 0.561
L1.Kärnten -0.060148 0.016627 -3.617 0.000
L1.Niederösterreich -0.095256 0.064910 -1.468 0.142
L1.Oberösterreich 0.174829 0.061410 2.847 0.004
L1.Salzburg 0.061588 0.032862 1.874 0.061
L1.Steiermark 0.230188 0.043167 5.333 0.000
L1.Tirol 0.488215 0.035118 13.902 0.000
L1.Vorarlberg 0.051432 0.030211 1.702 0.089
L1.Wien -0.053067 0.054788 -0.969 0.333
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158918 0.051316 3.097 0.002
L1.Burgenland -0.000155 0.035115 -0.004 0.996
L1.Kärnten 0.066384 0.018866 3.519 0.000
L1.Niederösterreich 0.200786 0.073647 2.726 0.006
L1.Oberösterreich -0.070195 0.069676 -1.007 0.314
L1.Salzburg 0.221361 0.037286 5.937 0.000
L1.Steiermark 0.112136 0.048977 2.290 0.022
L1.Tirol 0.085564 0.039844 2.147 0.032
L1.Vorarlberg 0.123746 0.034278 3.610 0.000
L1.Wien 0.103051 0.062163 1.658 0.097
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.360165 0.030410 11.844 0.000
L1.Burgenland 0.007802 0.020809 0.375 0.708
L1.Kärnten -0.025781 0.011180 -2.306 0.021
L1.Niederösterreich 0.229393 0.043644 5.256 0.000
L1.Oberösterreich 0.151350 0.041290 3.666 0.000
L1.Salzburg 0.052651 0.022096 2.383 0.017
L1.Steiermark -0.015789 0.029024 -0.544 0.586
L1.Tirol 0.123024 0.023612 5.210 0.000
L1.Vorarlberg 0.071556 0.020313 3.523 0.000
L1.Wien 0.047248 0.036838 1.283 0.200
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038660 0.161841 0.181568 0.169287 0.143694 0.128075 0.066402 0.219313
Kärnten 0.038660 1.000000 0.001841 0.132377 0.027150 0.099320 0.432185 -0.049355 0.101333
Niederösterreich 0.161841 0.001841 1.000000 0.346920 0.170894 0.314878 0.128498 0.192899 0.340368
Oberösterreich 0.181568 0.132377 0.346920 1.000000 0.234171 0.342156 0.178158 0.179902 0.272355
Salzburg 0.169287 0.027150 0.170894 0.234171 1.000000 0.153820 0.136988 0.153460 0.140481
Steiermark 0.143694 0.099320 0.314878 0.342156 0.153820 1.000000 0.159897 0.149100 0.095166
Tirol 0.128075 0.432185 0.128498 0.178158 0.136988 0.159897 1.000000 0.123280 0.162268
Vorarlberg 0.066402 -0.049355 0.192899 0.179902 0.153460 0.149100 0.123280 1.000000 0.019090
Wien 0.219313 0.101333 0.340368 0.272355 0.140481 0.095166 0.162268 0.019090 1.000000